#ifndef MODBUSRWPARAM_H
#define MODBUSRWPARAM_H

#include <QDebug>
#include <QMap>
#include <QMutex>
#include <QObject>
#include <QSettings>
#include <QTextCodec>
class ModbusRWParam {
public:
    struct ModbusIniMode {
        QString* name;
        quint16  adress;
        quint16  value_type;
        quint16  data_length;
    };
    struct ModbusListIniMode {
        QString* name;
        quint16  value_adress;              //抽样值地址
        quint16  value_length;              //抽样值长度
        quint16  control_adress;            //抽样控制地址
        quint16  control_take_value;        //抽样控制值（触发采样）
        quint16  control_clear_now_value;   //清除表控制值（不刷新显示）
        quint16  control_clear_back_value;  //清楚显示控制值（刷新显示，当前界面）
    };
    static ModbusRWParam& getInstance();
    static void           release();
    void                  readReadWiter();
    void                  printReadWiter();
    bool getWriterModbusIniMode( const QString& key, ModbusIniMode& initMode );
    bool getWriterModbusListIniMode( const QString& key, ModbusListIniMode& initMode );
    bool getWriterModbusIntHighFrequencey( const QString& key, int& index );
    QMap< QString, ModbusIniMode >* getAllReadModbusIniMode();
    QString getReadKeyByAddress( const int adress );

private:
    ModbusRWParam();
    ModbusRWParam( const ModbusRWParam& other );
    ModbusRWParam& operator=( const ModbusRWParam& othre );
    static QMutex                          mutex;
    static QScopedPointer< ModbusRWParam > instance;
    QMap< QString, ModbusIniMode >*     readModbusIniModeMap                   = nullptr;
    QMap< QString, ModbusIniMode >*     writerModbusInitModeMap                = nullptr;
    QMap< QString, ModbusListIniMode >* writerModbusListInitModeMap            = nullptr;
    QMap< QString, int >*               writerModbusInitHightFrequenceyModeMap = nullptr;
};

#endif  // MODBUSRWPARAM_H
